﻿using BBICMS.Application.ViewModels;
using BBICMS.Infrastructure;
using BBICMS.Infrastructure.Configs;
using BBICMS.Infrastructure.Email;
using BBICMS.Model;
using BBICMS.Repository;
using BBICMS.Resources;
using BBICMS.ViewModel;
using System;
using System.Web.Mvc;

namespace BBICMS.WebUI.Controllers
{

    public class ContactController : BaseController
    {     
        //
        // GET: /Contact/

        public ActionResult Index()
        {
            SendEmail evm = new SendEmail();            
            return View(evm);
        }

        [HttpPost]
        public JsonResult SendEmail(SendEmail se)
        {
            SMTPService ss = new SMTPService();
            se.Subject = "来自西普网站反馈";
            se.Body = string.Format("<p>{0}</p><p>发件人：{1} ({2}), 发件人邮箱：{3}</p>", se.Body, se.Name, se.Phone, se.Email);
            try
            {
                ss.SendMail(SettingsManager.Contact.MailTo, SettingsManager.Contact.MailCC, se.Subject, se.Body);
            }
            catch (Exception e)
            {
                AR.Setfailure(e.Message);
                return Json(AR, JsonRequestBehavior.DenyGet);
              
            }

            AR.SetSuccess(Messages.AlertSendSuccess);
            return Json(AR, JsonRequestBehavior.DenyGet);         
        }

    }
}
